package com.diligent.cloud.sfc.service;

import com.canny.commons.model.ListResult;
import com.canny.commons.page.IPage;
import com.diligent.cloud.logistics.container.model.LcmBoxFill;
import com.diligent.cloud.logistics.container.model.LcmBoxFillDetail;
import com.diligent.cloud.logistics.container.model.LcmBoxLedger;
import com.diligent.cloud.primary.data.model.rt.RtMachine;
import com.diligent.cloud.primary.data.model.rt.RtWorkCenter;
import com.diligent.cloud.sfc.model.MfgConsume;
import com.diligent.cloud.sfc.model.info.inventory.MatInventoryInfo;
import com.diligent.cloud.sfc.model.params.OrderListParams;
import com.diligent.cloud.sfc.model.params.inventory.MatInfoParams;
import com.diligent.cloud.wip.core.vo.GuideMaster;
import com.diligent.cloud.wip.panel.modle.WipStorageBin;
import com.diligent.cloud.workorder.model.WoOperationCompleteDetail;
import com.diligent.cloud.workorder.model.WoOrder;
import com.diligent.cloud.workorder.model.WoOrderCompleteDetail;
import com.diligent.cloud.workorder.model.WoOrderMatNeed;
import com.diligent.cloud.workordermd.model.MfgUserEnvironment;
import org.springframework.http.ResponseEntity;

import javax.validation.constraints.NotNull;
import java.security.Principal;
import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * IBaseService interface
 * 公共方法
 * @author xf107278
 * @date 3/28/2020
 */
public interface ISfcService {
    /**
     * 获取相同的工单
     * @param machCode
     * @param orderType
     * @return
     */
    List<WoOrder> getSameOrder(String machCode, Integer orderStatus, Integer orderType, Long systemId, Date produceDate);

    /**
     * 根据ID查询完工表信息
     * @param orderId
     * @return
     */
    WoOrderCompleteDetail getOrderCompleteByOrder(Long orderId,String WoOrder);

    /**
     * 通过工单号查找工序完工单明细
     * @param woOrder
     * @return
     */
    WoOperationCompleteDetail getOperationCompleteDetailByWoOrder(String woOrder);


    /**
     * 获取闲置框
     * @return
     */
    IPage<LcmBoxLedger> getIdleBox(String location, Long pageIndex, Long pageSize);


    /**
     * 获取物流运输的所有使用中框号
     * @param location 位置
     * @return
     */
    IPage<LcmBoxLedger> getLogisticsTransPortInfo(String location);

    /**
     * 获取相同位置的相同工单
     * @param location
     * @param orderId
     * @return
     */
    List<LcmBoxFill> getOrderSameLocation(String location, Long orderId, String matType);

    /**
     * 根据机台代码获取机台完整信息
     * @param machCode
     * @return
     */
    RtMachine getMachineByMachCode(String machCode);

    /**
     * 通过工单Id和账套Id 查询需求物料
     * @param orderId
     * @param systemId
     * @return
     */
    String getMatCodeByOrderIdAndSystemId(Long orderId,Long systemId,String  matType);

    /**
     * 通过工单Id和物料编号获取相对应的BatchCode
     * @param orderId
     * @param matCode
     * @return
     */
    String getBatchCodeByOrderId(Long orderId,String matCode);

    /**
     * 通过工单Id和物料类型获取所有的物料需求信息
     * @param orderId
     * @return
     */
    List<WoOrderMatNeed> getMatNeedByOrderIdAndMatType(@NotNull Long orderId, String matType);


    /**
     * 通过用户代码获取用户环境数据
     * @param userCode
     * @return
     */
    MfgUserEnvironment getUserEnvironmentByUserCode(String userCode);

    /**
     * 获取剪切列表信息
     * @param orderListParams
     * @return
     */
    ResponseEntity<ListResult> getCutOrderList(OrderListParams orderListParams);

    /**
     * 通过批次查询工单
     * @param prodBatch
     * @param machCode
     * @param systemId
     * @param orderType
     * @param isFinished
     * @return
     */
    ResponseEntity<ListResult> getSameOrderByProdBatch(String prodBatch, String machCode, Long systemId, Integer orderType, Integer isFinished,Integer operationIsFinished);

    /**
     * 获取物料列表
     * @param machCode 机台代码
     * @param orderType 工单类型
     * @param matCode 物料编码
     * @return
     */
    ListResult getMatList(String machCode, Integer orderType,String matCode);

    /**
     * 通过工作中心代码查找车间信息
     * @param workCenterCode
     * @return
     */
    RtWorkCenter getWorkCenterByCwocCode(String workCenterCode);

    /**
     * 添加物料消耗库存信息
     * @param params
     * @param principal
     * @return
     */
    MfgConsume addMatConsumerInventory(MatInfoParams params, Principal principal);

    /**
     * 添加详细物料库存信息
     * @param matInventoryInfo
     * @param mfgConsume
     * @return
     */
    MfgConsume addMatInventoryInfo(MatInventoryInfo matInventoryInfo, MfgConsume mfgConsume);


    /**
     * 通过工单查询批次
     * @param order
     * @return
     */
    String getProdBachByOrder(WoOrder order);

    /**
     * 添加工序完工单
     * @param order
     * @param prodBatch
     * @param principal
     */
    void addOperationComplete(WoOrder order, String prodBatch,Long asId,Boolean isOrderStart, Principal principal);

    /**
     * 整合wip仓单信息
     * @param boxId
     * @param wipStorageBin
     * @param workCenter
     * @param lcmBoxFillDetails
     * @return
     */
    GuideMaster generateWipStockOrderInfo(Long boxId,Long formId, WipStorageBin wipStorageBin, RtWorkCenter workCenter,  List<LcmBoxFillDetail> lcmBoxFillDetails);

    Long getPeriodId();

    String getMatType(String matType);

    Map<String,Integer> getProjectMatchingRate(Integer orderType, String projectName, String machCode);
}
